/*
XCommander Extension
http://www.xcommander.ch/
*/

function XCommanderEventListener() {
	this._listeners = [];
}

XCommanderEventListener.prototype = {
	fireEvent : function(event) {
		var type = event.type.toLowerCase();
		if( typeof this._listeners[type] != 'undefined') {
			var listeners = this._listeners[type];
			for(var i = 0; i < listeners.length; i++) {
				listeners[i](event)
			}
		}
		return false;
	},
	addEventListener : function(type, listener) {
		if( typeof listener == 'function') {
			var listeners = this._listeners[type.toLowerCase()] = this._listeners[type.toLowerCase()] || [];
			for(var i = 0; i < listeners.length; i++) {
				if(listeners[i] == listener) {
					return;
				}
			}
			listeners.push(listener);
		}
	},
	removeEventlistener: function(type, listener) {
		if( typeof this._listeners[type.toLowerCase()] != 'undefined') {
			var listeners = this._listeners[type.toLowerCase()];
			for(var i = 0; i < listeners.length; i++) {
				if(listeners[i] == listener) {
					listeners.splice(i, 1);
				}
			}
		}
	}
};